package br.edu.ifrn.dao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.Query;
import br.edu.ifrn.model.TipoDocumento;

public class TipoDocumentoDAO extends AbstractDAO {
	public TipoDocumentoDAO(EntityManager em) {
		AbstractDAO.em = em;
	}
	
	@Override
	public <E> List<E> listar() {
		Query q = em.createQuery("Select t From TipoDocumento t");
		return q.getResultList();
	}
	
	public TipoDocumento find(Long id) {
		return findById(TipoDocumento.class, id);
	}
	
	public boolean isAssociado(Long id){
		try{
			em.createQuery("Select d From Documento d where d.tipo.id = " + id).getSingleResult();
			return true;
		}
		catch (NoResultException e) {
			return false;
		}
	}
}
